package com.lgy.beans;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.lgy.enums.ProductStatusEnum;
import com.lgy.utils.EnumUtils;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;
import org.hibernate.annotations.DynamicUpdate;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;

/**
 * 商品
 */
@Table(name = "product_info")
@Entity
@Data
@ToString
@AllArgsConstructor
@NoArgsConstructor
@DynamicUpdate
public class ProductInfo implements Serializable {

    private static final long serialVersionUID = -5092840536629743154L;
    @Id
    private String productId;

    // 商品名称
    private String productName;

    // 单价
    private BigDecimal productPrice;

    // 库存
    private Integer productStock;

    // 描述
    private String productDescription;

    // 小图
    private String productIcon;

    // 状态 0 正常 1下架
    private Integer productStatus = ProductStatusEnum.UP.getCode();

    // 类目编号
    private Integer categoryType;

    private Date createTime;

    private Date updateTime;

    @JsonIgnore
    public ProductStatusEnum getProductStatusEnum() {
        return EnumUtils.getByCode(productStatus, ProductStatusEnum.class);
    }
}
